<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 投诉与反馈接口
 */
class Feedback extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = '*';

    /**
     * 提交反馈
     * 
     * @ApiTitle    (提交反馈)
     * @ApiMethod   (POST)
     * @ApiParams   (name="type", type="string", required=true, description="类型:complaint=投诉,consult=咨询,suggest=建议")
     * @ApiParams   (name="content", type="string", required=true, description="反馈内容")
     * @ApiParams   (name="images", type="array", required=false, description="图片列表")
     * @ApiReturn   ({
        "code": 1,
        "msg": "success",
        "data": null
      })
     */
    public function submit()
    {
        $this->auth->check();
        
        $params = $this->request->post();
        
        if(empty($params['type'])){
            $this->error('请选择反馈类型');
        }
        if(empty($params['content'])){
            $this->error('请输入反馈内容');
        }
        
        $data = [
            'user_id' => $this->auth->id,
            'type' => $params['type'],
            'phone' => isset($params['phone']) ? $params['phone'] : '',
            'content' => $params['content'],
            'images' => isset($params['images']) ? implode(',',$params['images']) : '',
            'createtime' => time()
        ];
        
        $result = \app\common\model\Feedback::create($data);
        if($result){
            $this->success('提交成功');
        }else{
            $this->error('提交失败');
        }
    }
}